﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

public class PropBase
{
    public string Name { get; } = "";
    public float BuyPrice { get; set; } = 0;
    public int Num { get; private set; } = 1;
    public int MaxNum { get; private set;}
    public bool IsConsumable { get; } = true;
    protected BaseData myCoolTime = new BaseData(1f);
    public BaseData CoolTime { get;private set; } = new BaseData(0f);


    private float lastUseTime=0;
    /// <summary>
    /// 再次获取物品
    /// </summary>
    /// <param name="getNum">获取到的物品数量</param>
    /// <returns>剩余未获取的数量</returns>
    public int GetItemSecond(int getNum)
    {
        Num += getNum;
        if (Num>MaxNum)
        {
            var r = MaxNum - Num;
            Num = MaxNum;
            return r;
        }
        return 0;
    }

    public bool UseItem()
    {
        if (IsConsumable)
        {
            Num--;
        }
        if (lastUseTime==0||Time.time-lastUseTime>= myCoolTime)
        {
            lastUseTime = Time.time;
            UsetItem_m();
            return true;
        }
        return false;
    }

    /// <summary>
    /// 计算冷却时间
    /// </summary>
    /// <param name="baseData">冷却时间增益</param>
    public void SulCoolTime(BaseData baseData)
    {
        CoolTime = myCoolTime + baseData;
    }

    protected virtual void UsetItem_m()
    {

    }
}

